<?php
// +----------------------------------------------------------------------
// | 十分彩网系统 [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Tuolaji <479923197@qq.com>
// +----------------------------------------------------------------------
/**
 */
namespace Admin\Controller;
use Common\Controller\AdminbaseController;
header('Content-type:text/html;charset=utf-8');


class DicController extends AdminbaseController{
	
	protected $users_model,$role_model;
	
    public function _initialize() {
        parent::_initialize();
    }

    //会员管理列表
    public function index(){
    	$where=array();
        $request=I('request.');		
        if(!empty($request['id'])){
            $where['parentid']=$request['id'];
        }
        
        $count = M('dictionary')
        ->where($where)->count();
        $size = $page = $this->page($count, 25);
        
        $data = M('dictionary')
        ->where($where)
        ->order("series ASC,create_time DESC,id DESC")
        ->limit($page->firstRow, $page->listRows)
        ->select();
        if(!empty($data) && is_array($data)){
        	$existdata=true;
        }else{
        	$existdata=false;
        }
        $this->assign("page", $page->show('Admin'));
        $this->assign("dic", $data);
        $this->assign("id", $request['id']);
        $this->assign("existdata", $existdata);
        $this->display();
        
    }

    public function add(){
    	$request=I('request.');
    	$this->assign("typeid", $request['typeid']);
    	$this->display();
    }
    
    // 报名记录添加提交
    public function add_post(){
    	if(IS_POST){
    		$data = I("post.frm");
    		$data['UserID'] = get_current_admin_id();
    		$data['create_ip'] = get_real_ip();
    		$data['parentid'] = $_POST['typeid'];
    		if (M('dictionary')->add($data)!==false) {
    			$this->success("添加成功",U("Dic/index",array("id"=>$_POST['typeid'])));
    		} else {
    			$this->error("添加失败！");
    		}
    	}
    }

    public function edit(){
    	$id = I('get.id',0,'intval');
    	$typeid = I('get.typeid',0,'intval');
    	$item = M("dictionary")
    	->where("id='$id'")
    	->find();
    	$this->assign("dic", $item);
    	$this->assign("id", $id);
    	$this->assign("typeid", $typeid);
    	$this->display();
    }
    public function edit_post(){
    	$id = I('post.id',0,'intval');
    	$typeid = I('post.typeid',0,'intval');
    	$data = I('post.frm');
    	$data['update_ip'] = get_real_ip();
    	$data['update_time'] = date("Y-m-d H:i:s",time());
    	$item = M("dictionary")->where(array("id"=>$id,"parentid"=>$typeid));
    	if ($item->save($data)!==false) {
    		$this->success("编辑成功",U("Dic/index",array("id"=>$typeid)));
    	} else {
    		$this->error("编辑失败！");
    	}
    }
	public function toggle(){
		if(!empty($_POST['ids']) && isset($_GET["display"])){
			$ids = I('post.ids/a');
			if (M('dictionary')->where(array('id'=>array('in',$ids)))->save(array('status'=>1))!==false) {
				$this->success("启用成功！");
			} else {
				$this->error("启用失败！");
			}
		}
		
		if(isset($_POST['ids']) && isset($_GET["hide"])){
			$ids = I('post.ids/a');
			if (M('dictionary')->where(array('id'=>array('in',$ids)))->save(array('status'=>2))!==false) {
				$this->success("禁用成功！");
			} else {
				$this->error("禁用失败！");
			}
		}
	}
	public function delete(){
		$id = I("get.id",0,"intval");
		if (M('dictionary')->where(array("id"=>$id))->delete()!==false) {
			$this->success("删除成功！");
		} else {
			$this->error("删除失败！");
		}
	}
	public function orders(){//广告排序
		$status = parent::_listorders(M('dictionary'),"series","id");
		if ($status) {
			$this->success("排序更新成功！");
		} else {
			$this->error("排序更新失败！");
		}
	}
}//结束
?>